#include "ObjGroup.h"

#include "ObjGroup.h"
#include "Error.h"

using namespace prog3d;
using namespace std;

ObjGroup::ObjGroup() {
  //ctor
  _active=true;
  _material=NULL;
}

ObjGroup::ObjGroup(string n) {
  _active=true;
  _material=NULL;
  _name=n;
}

int ObjGroup::nbFace() {
  return vf.size();
}

Material *ObjGroup::material() {
//  error("ObjGroup::material",__LINE__,__FILE__);
  return _material;
}

void ObjGroup::material(Material *m) {
//  error("ObjGroup::material",__LINE__,__FILE__);
  _material=m;
}

void ObjGroup::setGL(unsigned int drawMode) {
//  cout << "set material of group = " << name() << endl;

  if (_material) {
    _material->setGL();
    if (drawMode & DRAW_TEXTURE) _material->activeTexture();
    else {
      glDisable(GL_TEXTURE_2D);
    }
  }
//  cout << _material << endl;
}

void ObjGroup::enable() {
  _active=true;
}


void ObjGroup::disable() {
  _active=false;
}

void ObjGroup::addFacet(Facet *f) {
 // cout << "add in " << name() << endl;
  vf.addEnd(f);
}

void ObjGroup::draw(unsigned int drawMode) {
//cout << "nbre facette composante" << vf.size() << endl;
//cout << "groupe = " << name() << endl;
if (_active) {
  setGL(drawMode);
  vf.setDrawMode(drawMode);
//  cout << "DRAW MODE = " << drawMode << endl;
  vf.draw();
}
}

void ObjGroup::name(string s) {
  _name=s;
}

string ObjGroup::name() {
  return _name;
}

ObjGroup::~ObjGroup() {
  //dtor
}


